﻿#include "FITKSpectraFrequencyGenerator.h"

namespace Acoustics
{
    void FITKSpectraFrequencyGenerator::setFrequenceRange(const double& min, const double& max)
    {
        //设置范围
        _range[0] = min;
        _range[1] = max;
    }
    void FITKSpectraFrequencyGenerator::setDomainType(FITKGlobalFrequencyDomain::DomainType t)
    {
        _type = t;
    }
    void FITKSpectraFrequencyGenerator::setOctaveNum(const int n)
    {
        _octaveNum = n;
    }
    void FITKSpectraFrequencyGenerator::setBandWidth(const double w)
    {
        _bandWidth = w;
    }
    QList<double> FITKSpectraFrequencyGenerator::getFrequencyList()
    {
        //计算当前类型下的全部的频率
        FITKGlobalFrequencyDomain d;
        d.setDomainType(_type);
        d.setOctaveNum(_octaveNum);
        d.setBandWidth(_bandWidth);
        d.setStartFrequence(_range[0]);
        d.setEndFrequence(_range[1]);
        
        //得到全部频率
        QList<double> globalfs = d.getFrequenceList();
        //固定带宽直接返回全部链表
        if (globalfs.isEmpty() || _type == FITKGlobalFrequencyDomain::DomainType::DTConstantBandWidth)
            return globalfs;

        //对频率范围伸长，避免第一个和最后一个被筛除,参数需要调整 
        const double minV = _range[0] * 0.999;
        const double maxV = _range[1] * 1.001;

        QList<double> fs;
        //遍历全部频率值
        for (double cv : globalfs)
        {
            //判断是否在范围内
            if (cv >= minV && cv <= maxV)
                fs.append(cv);
        }

        return fs;
    }
}


